package com.dl7.mvp.module.video.list;

import android.util.Log;

import com.dl7.mvp.api.RetrofitService;
import com.dl7.mvp.local.table.AlbumsListBean;
import com.dl7.mvp.module.base.IBasePresenter;
import com.dl7.mvp.module.base.ILoadDataView;

import java.util.List;

import rx.Subscriber;

public class AlbumsListPresenter implements IBasePresenter {
    final private ILoadDataView mView;
    private int mID;

    public AlbumsListPresenter(ILoadDataView view, int id) {
        this.mView = view;
        this.mID = id;
    }

    @Override
    public void getData() {
        Subscriber subscriber = new Subscriber<List<AlbumsListBean.DataBean>>() {
            @Override
            public void onCompleted() {
                Log.e("12345", "onCompleted: ");
            }

            @Override
            public void onError(Throwable e) {
                Log.e("12345", "onError");
            }

            @Override
            public void onNext(List<AlbumsListBean.DataBean> categoryList) {
                Log.e("12345", "categoryList: " + categoryList.size());
                if (categoryList != null) {
                    for (AlbumsListBean.DataBean category : categoryList) {
                        if (category.getId() == mID) {
                            mView.loadData(category.getAlbums());
                        }
                    }
                }
            }
        };
        RetrofitService.getCategoriesVideoList(0, 100, 20)
                .subscribe(subscriber);
    }

    @Override
    public void getMoreData() {
    }

}
